const { post } = require('./request.js');

/**
 * 查询每月总收入
 * @param {string} month 查询月份 yyyy-MM
 * @param {string} account 员工工号
 * @returns {Promise<Object>} API响应
 */
const getMonthlySalary = async (month, account) => {
  try {
    
    // 手动构建查询参数字符串
    const params = [];
    if (month) {
      params.push(`month=${encodeURIComponent(String(month))}`);
    }
    if (account) {
      params.push(`account=${encodeURIComponent(String(account))}`);
    }
    const queryString = params.length > 0 ? `?${params.join('&')}` : '';
    
    
    const response = await post(`/checkSalary/getSalaryMonth${queryString}`, {});
    
    
    if (response.code === 200 || response.code === 0) {
      return {
        success: true,
        data: response.data,
        message: response.message || '获取成功'
      };
    } else {
      return {
        success: false,
        message: response.message || '获取每月总收入失败'
      };
    }
  } catch (error) {

    return {
      success: false,
      message: error.message || '网络请求失败'
    };
  }
};

/**
 * 查询每月每天的工资列表
 * @param {string} month 查询月份 yyyy-MM
 * @param {string} account 员工工号
 * @returns {Promise<Object>} API响应
 */
const getDailySalaryList = async (month, account) => {
  try {
    
    // 手动构建查询参数字符串
    const params = [];
    if (month) {
      params.push(`month=${encodeURIComponent(String(month))}`);
    }
    if (account) {
      params.push(`account=${encodeURIComponent(String(account))}`);
    }
    const queryString = params.length > 0 ? `?${params.join('&')}` : '';
    
    
    const response = await post(`/checkSalary/salaryDay${queryString}`, {});
    
    
    if (response.code === 200 || response.code === 0) {
      return {
        success: true,
        data: response.data,
        message: response.message || '获取成功'
      };
    } else {
      return {
        success: false,
        message: response.message || '获取每天工资列表失败'
      };
    }
  } catch (error) {

    return {
      success: false,
      message: error.message || '网络请求失败'
    };
  }
};

module.exports = {
  getMonthlySalary,
  getDailySalaryList
}; 